﻿@model KL.Store.Web.Models.CartModel
@using KL.Store.Core
@{
    var imageType = "_s";
    if (Parameters.Theme == "HA")
    {
        imageType = "_w";
    }   
}
<div class="content">
    @if (Parameters.Theme == "DK" || Parameters.Theme == "EO")
    {
        <h1>Sepetim</h1>
    }
    <div class="bg-info bs-bg" style="margin-bottom: 15px;">
        @Html.Raw(Parameters.CartHeadText)
    </div>
    @{Html.RenderAction("ManageContentLink", "Partials", new { id = 440 });}
    @{if (Model.Products.Count == 0)
      {
        <text>Sepetinizde henüz ürün bulunmamaktadır.</text>
      }
      else
      { 
        <div class="shop-cart">
            <div class="shop-cart-outer">
                <div class="shop-cart-inner">
                    <table class="table-responsive @{if (Parameters.Theme == "DK" | Parameters.Theme == "EO")
                                                     {<text> table-bordered</text>}}" style="width: 100%;">
                        <thead>
                            <tr class="shop-cart-table-head">
                                <td class="image">Ürün</td>
                                <td class="name">&nbsp;</td>
                                <td class="quantity">Adet</td>
                                <td class="price">Birim Fiyat</td>
                                <td style="border-right: none;" class="total">Toplam</td>
                                @if (Parameters.Theme == "HA")
                                {
                                    <td class="delete">Sil</td>
                                }
                            </tr>
                        </thead>
                        <tbody>
                            @{
                                List<string> kargoUyari = new List<string>();
                                List<int> kargoEklenenler = new List<int>();
                            }
                            @foreach (var item in Model.Products)
                            {
                                KL.Store.Core.Domain.CargoDiscount CgDiscount = KL.Store.Data.dbCart.GetCargoDiscountSummary(item.ProductId);
                                if (CgDiscount.SepetMinTutar != 0 && !string.IsNullOrEmpty(Convert.ToString(CgDiscount.SepetMinTutar)) && CgDiscount.SepetMinTutar > (item.Price * item.Qty))
                                {
                                    if (!kargoEklenenler.Contains(CgDiscount.IdGrup))
                                    {
                                        kargoUyari.Add("Sepetinizde bulunan " + CgDiscount.Aciklama + " kategorisindeki ürünlerde " + CgDiscount.SepetMinTutar + " TL ve üzeri alışverişlerinizde kargo ücreti " + (Convert.ToDouble(CgDiscount.KargoUcret) * 1.18).ToString("###,###,##0.00") + " TL’ye sabitlenmektedir. Bu fırsattan yararlanmak ve daha az kargo ücreti ödemek için sepetinize yeni ürünler ekleyebilirsiniz. <br /><a href=\"" + CgDiscount.LinkUrl + "\" class=\"btn btn-custom2 right\">Yeni Ürün Ekle</a>");
                                        kargoEklenenler.Add(CgDiscount.IdGrup);
                                    }
                                }
                                <tr>
                                    <td class="image">
                                        <a class="hizliBak" href="javascript:void(0);" title="@(item.ProductName.Replace("\"", ""))" data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount">
                                            @if (item.ProductImageCount > 0)
                                            {
                                                <img alt="@(item.ProductName.Replace("\"", ""))" src="@(Parameters.WebSiteImageUrl)/product-small/@(item.ProductId)_1@(imageType).jpg" id="ip_@item.ProductId"  /> 
                                            }
                                            else if (item.ProductImageCount2 > 0)
                                            {
                                                <img alt="@(item.ProductName.Replace("\"", ""))" src="@(Parameters.WebSiteImageUrl)/product-small/@(item.UstUrunId)_1@(imageType).jpg" id="ip_@item.ProductId"  /> 
                                            }
                                            else
                                            {
                                                <img alt="@(item.ProductName.Replace("\"", ""))" src="/Images/@Parameters.Theme/product-image-not-found-200x.jpg" id="ip_@item.ProductId"  />
                                            }
                                        </a>
                                    </td>
                                    <td class="name">
                                        <a class="hizliBak" href="javascript:void(0);" title="@(item.ProductName.Replace("\"", ""))" data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount">@(item.ProductName + (!string.IsNullOrEmpty(item.Model) ? " - " + item.Model : ""))</a>
                                        @if (item.InstallmentNeeded)
                                        {
                                            if (item.InstallmentSelected)
                                            {
                                            <text><br />
                                            Kurulum Seçildi (</text>@item.InstallmentPrice.ToString("###,###,##0.00")<text> TL Kdv Dahil)</text>
                                            }
                                            else
                                            {
                                            <text><br />
                                            Kurulum Seçilmedi</text>
                                            }
                                        }
                                        @if (!string.IsNullOrEmpty(item.ListOwner))
                                        {
                                            <text><br />@item.ListOwner</text>
                                        }
                                    </td>
                                    <td class="quantity">
                                        @if (Parameters.Theme == "HA")
                                        {
                                            <div class="quantity-value">
                                                @if (item.Qty > 0)
                                                {
                                                    <div class="qtitext">
                                                        <input type="text" id="qty_@(item.ListId)_@(item.ProductId)" value="@item.Qty.ToString("#####")" size="2" readonly="readonly" />
                                                    </div>
                                                }
                                                else
                                                {
                                                    <text>Hediye Destek</text>
                                                }
                                                <div class="qtibuttons">
                                                    <a class="icrLink" id="@("icr_" + item.ListOwnerId)_@(item.ListId)_@(item.ProductId)"></a>
                                                    <a class="dcrLink" id="@("dcr_" + item.ListOwnerId)_@(item.ListId)_@(item.ProductId)"></a>
                                                </div>
                                            </div>
                                        }
                                        else
                                        {
                                            <div class="quantity-value">
                                                <a id="dcr_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="dcrLink">
                                                    <i class="glyphicon glyphicon-minus"></i>
                                                </a>
                                                @if (item.Qty > 0)
                                                {
                                                    <input type="text" id="qty_@(item.ListId)_@(item.ProductId)" value="@item.Qty.ToString("#####")" size="1" />
                                                }
                                                else
                                                {
                                                    <text>Hediye Destek</text>
                                                }
                                                <a id="icr_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="icrLink">
                                                    <i class="glyphicon glyphicon-plus"></i>
                                                </a>
                                            </div>
                                            <div class="wrapper mt5">
                                                @if (item.Qty > 0)
                                                {
                                                    <a id="up_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="upLink">
                                                        <i class="glyphicon glyphicon-refresh"></i>
                                                    </a>
                                                }
                                                <a id="rm_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="rmLink">
                                                    <i class="glyphicon glyphicon-remove"></i>
                                                </a>
                                            </div>
                                            
                                        }
                                    </td>
                                    <td class="price" style="text-align: right">@item.Price.ToString("###,###,##0.00") @item.Currency</td>
                                    <td style="border-right: 0; text-align: right;" class="total">@if (item.Qty > 0)
                                                                                                  {
                                        @((item.Price * item.Qty).ToString("###,###,##0.00"))
                                                                                                  }
                                                                                                  else
                                                                                                  {
                                        @(item.Price.ToString("###,###,##0.00"))
                                                                                                  }  @item.Currency</td>
                                    @if (Parameters.Theme == "HA")
                                    {
                                        <td class="delete">
                                            <a id="rm_@(item.ListOwnerId)_@(item.ListId)_@(item.ProductId)" class="rmLink">
                                                <i class="glyphicon glyphicon-remove"></i>
                                            </a>
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                        @{ var pricesColspan = "";
                           if (Parameters.Theme == "HA")
                           {
                               pricesColspan = " colspan=2";
                           }
                        }
                        <tfoot>
                            <tr>
                                <td style="text-align: right" class="name" colspan="4">Ara toplam :<br />
                                    KDV :<br />
                                    Taksitli Toplam Fiyat:
                                    @if (Model.TotalPrice != Model.TotalPriceCreditCard)
                                    {<br /><text><b>Tek Çekim Toplam Fiyat:</b></text> }</td>
                                <td style="text-align: right" class="total"@(pricesColspan)>@Model.Price.ToString("###,###,###,##0.00") TL<br />
                                    @Model.Tax.ToString("###,###,###,##0.00") TL<br />
                                    @Model.TotalPrice.ToString("###,###,###,##0.00") TL
                                    @if (Model.TotalPrice != Model.TotalPriceCreditCard)
                                    {<br />
                                        <b>@Model.TotalPriceCreditCard.ToString("###,###,###,##0.00") TL</b>}

                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
                                    if (kargoUyari.Count() > 0)
                                    {
        <br />
                                        foreach (var item in kargoUyari)
                                        {
        @Html.Raw("<div class=\"bg-danger bs-bgdar\" style=\"margin-bottom: 15px;\"><p><span class=\"glyphicon glyphicon-info-sign\"></span>&nbsp;" + item + "</p><div class=\"clearfix\"></div></div>");
                                        }
        <div class="clearfix"></div>
                                    }
                                    if (Parameters.OnlyUseCCandMTforOpportunityProduct && Model.Products.Where(o => o.OpportunityProduct).Count() > 0)
                                    {
        <div class="bg-info bs-bgb" style="margin-bottom: 15px;">
            <p class="alignright"><span class="glyphicon glyphicon-info-sign"></span>&nbsp;Sepetinizde fırsat ürünleri bulunmaktadır, sadece kredi kartı ya da havale ile ödeme yapabilirsiniz.</p>
            <div class="clearfix"></div>
        </div>
        <div class="clearfix"></div>  
                                    }                        
        <div class="left checkout-button hidden-xs">
            <a class="btn btn-custom3" href="/"><span><i class="glyphicon glyphicon-chevron-left"></i>&nbsp;Alışverişe devam et</span></a>
        </div>
        <div class="right checkout-button">
            <a class="btn btn-custom1" href="@(Parameters.WebSiteSecureUrl)/Cart/Checkout"><span>Sepeti Onayla&nbsp;<i class="glyphicon glyphicon-chevron-right"></i></span></a>
        </div>
                                    if (Parameters.AllowVisitorsToUsingCart && Model.AccountType == 1)
                                    {
        <div class="right checkout-button">
            <a class="btn btn-custom3" href="@(Parameters.WebSiteSecureUrl)/Account/Login?ReturnUrl=/Cart/Index"><span><i class="glyphicon glyphicon-floppy-disk"></i>&nbsp;Sepeti Kaydet</span></a>
        </div>
        
                                    }
        <div class="clearfix"></div>
      }
    }
</div>
@Html.Raw(ViewData["cartMessage"])
<script type="text/javascript">
    $('a.cgLink').click(function ()
    {
        var qsId = $(this).attr('id').split("_")[1];
        $('.contentCart').load('/Categories/Get', { id: qsId });
        return false;
    });

    $('a.prLink').click(function ()
    {
        var qsId = $(this).attr('id').split("_")[1];
        $('.contentCart').load('/Products/Get', { id: qsId });
        return false;
    });

    $('a.prdLink2').click(function ()
    {
        var qsId = $(this).attr('id').split("_")[1];
        $('.contentCart').load('/Product/Get', { id: qsId });
        return false;
    });

    $('a.rmLink').click(function ()
    {
        if (!confirm("Seçtiğiniz ürün sepetinizden kaldırılacaktır, emin misiniz?")) return false;
        var qsUserId = $(this).attr('id').split("_")[1];
        var qsId1 = $(this).attr('id').split("_")[2];
        var qsId2 = $(this).attr('id').split("_")[3];

        $('.contentCart').load('/Cart/Remove', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2 }, function () { RefreshCartSummary(); });
        return false;
    });

    $('a.upLink').click(function ()
    {
        var qsUserId = $(this).attr('id').split("_")[1];
        var qsId1 = $(this).attr('id').split("_")[2];
        var qsId2 = $(this).attr('id').split("_")[3];
        var qty = $('#qty_' + qsId1.toString() + "_" + qsId2.toString()).val();

        $('.contentCart').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty }, function () { RefreshCartSummary(); });
        return false;
    });

    $('a.dcrLink').click(function ()
    {
        var qsUserId = $(this).attr('id').split("_")[1];
        var qsId1 = $(this).attr('id').split("_")[2];
        var qsId2 = $(this).attr('id').split("_")[3];
        var qty = $('#qty_' + qsId1.toString() + "_" + qsId2.toString()).val();
        qty--;
        $('.contentCart').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty }, function () { RefreshCartSummary(); });
        return false;
    });

    $('a.icrLink').click(function ()
    {
        var qsUserId = $(this).attr('id').split("_")[1];
        var qsId1 = $(this).attr('id').split("_")[2];
        var qsId2 = $(this).attr('id').split("_")[3];
        var qty = $('#qty_' + qsId1.toString() + "_" + qsId2.toString()).val();
        qty++;
        $('.contentCart').load('/Cart/Update', { ListOwnerId: qsUserId, listId: qsId1, id: qsId2, 'qty': qty }, function () { RefreshCartSummary(); });
        return false;
    });

    $(document).ready(function ()
    {
        $('a.addToCart').click(function ()
        {
            var qsId = $(this).attr('id').split("_")[1];
            if ($('#cart').load('/Cart/Insert', { id: qsId }))
            {
                RefreshCart();
            }
            $('body,html').animate({
                scrollTop: 0
            }, 800);
            $(".sepetFull img").delay(1000).fadeOut("slow").fadeIn("slow");
            return false;
        });
        if ($(window).width() < 768)
        {
            $(".shop-cart table tbody td.image").remove();
            $(".shop-cart table thead td.name").remove();
            $(".shop-cart table tfoot td.name").attr("colspan", "2");
            $(".shop-cart table tfoot td.total").attr("colspan", "2");
        }
    });

    function RefreshCartSummary()
    {
        $('#cart').load('/Cart/GetSummary2', {});
        $('#sepetMinimalContent').load('/Cart/GetMinimal', { showPhotos: true, ShowAcrIcrLinks: true });
    }

    function RefreshCart()
    {
        $('.contentCart').load('/Cart/Get', {});
    }

</script>
